﻿using System;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using FlexiCache;

namespace System.Web
{
    public static class HttpResponseExtensions
    {
        /// <summary>
        /// Method removes cached data from the output cache using specified meta tags.
        /// </summary>
        /// <remarks>If all parameters are empty, the the request is ignored.</remarks>
        /// <remarks>This is applicable to Custom External Output Cache Provider.</remarks>
        /// <param name="path">The relative path used to request the data; should not include the query string. Can be empty or null.</param>
        /// <param name="metaTags">The collection of metatags to locate the data.</param>
        public static void RemoveOutputCacheItem(this HttpResponse response, string path, string[] metaTags)
        {
            ExternalOutputCacheApi.RemoveOutputCacheItem(path, metaTags);
        }

        /// <summary>
        /// Method removes cached data from the output cache using specified meta tags.
        /// </summary>
        /// <remarks>If metaTags array is empty, the the request is ignored.</remarks>
        /// <remarks>This is applicable to Custom External Output Cache Provider.</remarks>
        /// <param name="metaTags">The collection of metatags to locate the data.</param>
        public static void RemoveOutputCacheItem(this HttpResponse response, string[] metaTags)
        {
            ExternalOutputCacheApi.RemoveOutputCacheItem(null, metaTags);
        }

        /// <summary>
        /// Method removes cached data from the output cache using specified path and parameter as meta tags.
        /// </summary>
        /// <remarks>If both, path and parameter are empty, the the request is ignored.</remarks>
        /// <remarks>This is applicable to Custom External Output Cache Provider.</remarks>
        /// <param name="path">The relative path used to request the data; should not include the query string. Can be empty or null.</param>
        /// <param name="parameterName">The name of parameter that should be used to build metatags to locate the data. This cannot be empty, otherwise is ignored.</param>
        /// <param name="parameterValue">The name of parameter that should be used to build metatags to locate the data. This can be empty or null.</param>
        public static void RemoveOutputCacheItem(this HttpResponse response, string path, string parameterName, string parameterValue)
        {
            ExternalOutputCacheApi.RemoveOutputCacheItem(path, parameterName, parameterValue);
        }

        /// <summary>
        /// Method removes cached data from the output cache using specified parameters as meta tags.
        /// </summary>
        /// <remarks>If both, path and parameters are empty, the the request is ignored.</remarks>
        /// <remarks>This is applicable to Custom External Output Cache Provider.</remarks>
        /// <param name="path">The relative path used to request the data; should not include the query string. Can be empty or null.</param>
        /// <param name="parametersCollection">The collection of name-value parameters that should be used to build metatags to locate the data. 
        /// The metatags are built using name=value pattern.</param>
        public static void RemoveOutputCacheItem(this HttpResponse response, string path, NameValueCollection parametersCollection)
        {
            ExternalOutputCacheApi.RemoveOutputCacheItem(path, parametersCollection);
        }
    }

    public static class HttpCachePolicyExtensions
    {
        /// <summary>
        /// Sets explicit output cache meta tag associated with the response.
        /// </summary>
        /// <remarks>This is applicable to Custom External Output Cache Provider.</remarks>
        /// <param name="metatag">Meta tag string to add.</param>
        public static void SetMetaTag(this HttpCachePolicy outputCache, string metatag)
        {
            CachedResourceFinder.SetExplicitMetatag(metatag);
        }
    }
}
